<?php

namespace app\api\controller;

use app\admin\validate\BaseValidate;
use app\domain\admin\DeviceDataDomain;
use think\response\Json;

class DeviceData extends Common
{
    public function getDeviceData(DeviceDataDomain $domain): Json
    {
        try {
            $params = request()->param();
            $validate = validate(BaseValidate::class);
            if (!$validate->scene('retrieve')->check($params)) {
                throw new \Exception($validate->getError());
            }

            $result = $domain->retrieve($params['page'], $params['pageSize'], $params['search'] ?? []);
            return jsonReturn((bool)$result, lang($domain->errMsg), $result, $domain->statusCode);
        } catch (\Exception $e) {
            return jsonReturn(false, lang($e->getMessage()));
        }
    }
}